/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * FinalizarChamado.java
 *
 * Created on Nov 22, 2011, 10:59:15 AM
 */
package br.fesppr.sacob.gui;

import br.fesppr.sacob.dao.AtendimentoDAO;
import br.fesppr.sacob.dto.AtendimentoDTO;
import javax.swing.text.MaskFormatter;

/**
 *
 * @author chrestenzen
 */
public class FinalizarChamado extends javax.swing.JDialog {

    /** Creates new form FinalizarChamado */
    public FinalizarChamado(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        lblTxt2 = new javax.swing.JLabel();
        lblProtocolo = new javax.swing.JLabel();
        lblData = new javax.swing.JLabel();
        lblSolucao = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        txtSolucao = new javax.swing.JTextArea();
        lblStatus = new javax.swing.JLabel();
        txtProtocolo = new javax.swing.JTextField();
        btnBuscar = new javax.swing.JButton();
        lblCliente = new javax.swing.JLabel();
        txtCliente = new javax.swing.JTextField();
        lblProduto = new javax.swing.JLabel();
        txtProduto = new javax.swing.JTextField();
        comboStatus = new javax.swing.JComboBox();
        btnFinalizarChamado = new javax.swing.JButton();
        try
        {
            MaskFormatter formatterData = new MaskFormatter("##/##/####");
            formatterData.setPlaceholderCharacter('_');
            txtData = new javax.swing.JFormattedTextField();
            jScrollPane2 = new javax.swing.JScrollPane();
            txtDescricao = new javax.swing.JTextArea();
            lblSolucao1 = new javax.swing.JLabel();
            jSeparator2 = new javax.swing.JSeparator();
            lblStatus1 = new javax.swing.JLabel();
            comboSatisfacao = new javax.swing.JComboBox();

            setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
            setTitle("SACOB -  Finalizar Atendimentos");
            setResizable(false);

            jLabel1.setFont(new java.awt.Font("DejaVu Sans", 1, 12));
            jLabel1.setForeground(new java.awt.Color(3, 3, 3));
            jLabel1.setText("SACOB - Sistema de Atendimento ao Cliente Belíssima ");

            lblTxt2.setFont(new java.awt.Font("Tahoma", 0, 10));
            lblTxt2.setText("Finalizar Chamado");

            lblProtocolo.setFont(new java.awt.Font("Tahoma", 0, 12));
            lblProtocolo.setText("Protocolo:");

            lblData.setFont(new java.awt.Font("Tahoma", 0, 12));
            lblData.setText("Data:");

            lblSolucao.setFont(new java.awt.Font("Tahoma", 0, 10));
            lblSolucao.setText("Solução:");

            txtSolucao.setColumns(20);
            txtSolucao.setRows(5);
            jScrollPane1.setViewportView(txtSolucao);

            lblStatus.setFont(new java.awt.Font("Tahoma", 0, 12));
            lblStatus.setText("Status:");

            btnBuscar.setText("Buscar");
            btnBuscar.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    btnBuscarActionPerformed(evt);
                }
            });

            lblCliente.setFont(new java.awt.Font("Tahoma", 0, 12));
            lblCliente.setText("Nome do Cliente:");

            txtCliente.setEditable(false);
            txtCliente.setForeground(new java.awt.Color(204, 204, 204));

            lblProduto.setFont(new java.awt.Font("Tahoma", 0, 12));
            lblProduto.setText("Produto:");

            txtProduto.setEditable(false);
            txtProduto.setForeground(new java.awt.Color(204, 204, 204));

            comboStatus.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Concluído", " " }));

            btnFinalizarChamado.setText("Finalizar Chamado");
            btnFinalizarChamado.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    btnFinalizarChamadoActionPerformed(evt);
                }
            });

        }catch (Exception e ){}
        txtData.setBackground(new java.awt.Color(240, 240, 240));

        txtDescricao.setColumns(20);
        txtDescricao.setEditable(false);
        txtDescricao.setFont(new java.awt.Font("DejaVu Sans", 0, 12));
        txtDescricao.setForeground(new java.awt.Color(102, 102, 102));
        txtDescricao.setRows(5);
        jScrollPane2.setViewportView(txtDescricao);

        lblSolucao1.setFont(new java.awt.Font("Tahoma", 0, 10));
        lblSolucao1.setText("Descrição:");

        lblStatus1.setFont(new java.awt.Font("Tahoma", 0, 12));
        lblStatus1.setText("Satisfação:");

        comboSatisfacao.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Excelente", "Ótimo", "Bom", "Regular", "Ruim", "Pésimo" }));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lblTxt2)
                .addContainerGap(308, Short.MAX_VALUE))
            .addComponent(jSeparator2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
            .addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(51, Short.MAX_VALUE)
                .addComponent(jLabel1)
                .addGap(38, 38, 38))
            .addGroup(layout.createSequentialGroup()
                .addGap(110, 110, 110)
                .addComponent(lblProtocolo)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txtProtocolo, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnBuscar)
                .addContainerGap(115, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lblCliente)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txtCliente, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lblProduto)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txtProduto, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(17, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                .addGap(128, 128, 128)
                .addComponent(lblData)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txtData, javax.swing.GroupLayout.DEFAULT_SIZE, 88, Short.MAX_VALUE)
                .addGap(151, 151, 151))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jScrollPane2)
                        .addContainerGap())
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(lblSolucao1)
                        .addGap(343, 343, 343))))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jScrollPane1)
                        .addContainerGap())
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(lblSolucao)
                        .addGap(350, 350, 350))))
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lblStatus)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(comboStatus, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 112, Short.MAX_VALUE)
                .addComponent(lblStatus1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(comboSatisfacao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(30, 30, 30))
            .addGroup(layout.createSequentialGroup()
                .addGap(137, 137, 137)
                .addComponent(btnFinalizarChamado)
                .addContainerGap(144, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 2, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnBuscar)
                    .addComponent(txtProtocolo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblProtocolo))
                .addGap(5, 5, 5)
                .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 2, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lblTxt2)
                .addGap(4, 4, 4)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtData, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblData))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblCliente)
                    .addComponent(txtCliente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblProduto)
                    .addComponent(txtProduto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(lblSolucao1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 66, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(lblSolucao)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblStatus)
                    .addComponent(comboStatus, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblStatus1)
                    .addComponent(comboSatisfacao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(btnFinalizarChamado)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void btnBuscarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBuscarActionPerformed
// TODO add your handling code here:
    AtendimentoDTO dtoa = new AtendimentoDTO();
    AtendimentoDAO daoa = new AtendimentoDAO();
    
    int protocolo = (Integer.parseInt(txtProtocolo.getText()));
    
    dtoa = daoa.listaProtocolo(protocolo);
    
    txtCliente.setText(dtoa.getNomeCliente());
    txtProduto.setText(dtoa.getProduto());
    txtData.setText(dtoa.getData());
    txtDescricao.setText(dtoa.getDescricao());
}//GEN-LAST:event_btnBuscarActionPerformed

private void btnFinalizarChamadoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnFinalizarChamadoActionPerformed
// TODO add your handling code here:
    AtendimentoDTO finalizaAtendimento = new AtendimentoDTO();
    AtendimentoDAO atendimentodao = new AtendimentoDAO();
    
    finalizaAtendimento.setSolucao(txtSolucao.getText());
    finalizaAtendimento.setStatus(comboStatus.getSelectedItem().toString());
    finalizaAtendimento.setSatisfacao(comboSatisfacao.getSelectedItem().toString());
    atendimentodao.finalizarAtendimento(finalizaAtendimento, (Integer.parseInt(txtProtocolo.getText())));
    
    
}//GEN-LAST:event_btnFinalizarChamadoActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(FinalizarChamado.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(FinalizarChamado.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(FinalizarChamado.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(FinalizarChamado.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the dialog */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                FinalizarChamado dialog = new FinalizarChamado(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {

                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnBuscar;
    private javax.swing.JButton btnFinalizarChamado;
    private javax.swing.JComboBox comboSatisfacao;
    private javax.swing.JComboBox comboStatus;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JLabel lblCliente;
    private javax.swing.JLabel lblData;
    private javax.swing.JLabel lblProduto;
    private javax.swing.JLabel lblProtocolo;
    private javax.swing.JLabel lblSolucao;
    private javax.swing.JLabel lblSolucao1;
    private javax.swing.JLabel lblStatus;
    private javax.swing.JLabel lblStatus1;
    private javax.swing.JLabel lblTxt2;
    private javax.swing.JTextField txtCliente;
    private javax.swing.JFormattedTextField txtData;
    private javax.swing.JTextArea txtDescricao;
    private javax.swing.JTextField txtProduto;
    private javax.swing.JTextField txtProtocolo;
    private javax.swing.JTextArea txtSolucao;
    // End of variables declaration//GEN-END:variables
}
